<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title></title>
	<link rel="stylesheet" href="../../../component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="" lay-filter="form-filter">
	<div class="mainBox">
		<div class="main-container">
			<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-card-body">
						<form class="layui-form" action="">
							<div class="layui-row">
								<div class="layui-col-xs3 layui-col-sm6 layui-col-md3">
									<div class="layui-form-item">
										<div class="layui-input-group">
											<div class="layui-input-prefix">课程名称</div>
											<input type="text" name="name" placeholder="请输入字典名称" class="layui-input">
										</div>
									</div>
								</div>
								<div class="layui-col-xs3 layui-col-sm3 layui-col-md3">
									<div class="layui-form-item">
										<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="data-table-query-filter">
											<i class="layui-icon layui-icon-search"></i>查询
										</button>
										<button type="reset" class="pear-btn pear-btn-md">
											<i class="layui-icon layui-icon-refresh"></i>重置
										</button>
									</div>
								</div>
							</div>
						</form>
					</div>
				</div>
				<table id="course-table" lay-filter="course-table"></table>
			</div>
		</div>
	</div>
	<div class="bottom">
		<div class="button-container">
			<button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="submit-filter">
				<i class="layui-icon layui-icon-ok"></i>提交
			</button>
			<button type="reset" class="pear-btn pear-btn-sm">
				<i class="layui-icon layui-icon-refresh"></i>取消
			</button>
		</div>
	</div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
	layui.use(['common','table','form', 'jquery', 'dict'], function() {
		let common = layui.common;
		let table = layui.table;
		let form = layui.form;
		let $ = layui.jquery;
		let dict = layui.dict;
		let url = layui.url();
		let id = url.search.id;

		let cols = [[
			{ type: 'checkbox', hide: false },
			{ field: 'name', title: '课程名称',  width: 180 },
			{ field: 'type', title: '课程类型' , width: 100 },
			{ field: '', title: '所属分类' , width: 120 },
			{ field: '', title: '课时' , width: 80 },
			{ field: 'sort', title: '排序', width: 70 },
			{ field: 'status', title: '状态', width: 120, event: 'disabled', templet: function(d) {
					return dict.labelStatus('common_status', d.status, true);
				} }
		]];

		table.render({
			elem: '#course-table',
			url: "/crm/course/page?notInCoursePackageId="+id,
			request: {
				pageName: 'pageNo', // 页码的参数名称，默认：page
				limitName: 'pageSize' // 每页数据条数的参数名，默认：limit
			},
			parseData: function(res) {
				let total = !$.vtl.isBlank(res.data)? res.data.total : 0;
				let list = !$.vtl.isBlank(res.data)? res.data.list : [];
				return {
					"code": 0,
					"msg": 'SUCCESS',
					"count": total,
					"data": list
				};
			},
			page: true,
			cols: cols,
			skin: 'grid',
			height: 'full-148'
		});
		form.on('submit(data-table-query-filter)', function(data) {
			window.refreshCourse(data.field);
			return false;
		});

		form.on('submit(submit-filter)', function(data) {
			data.field.coursePackageId = id;
			data.field.courseIds = common.getTableCheckIds('course-table');
			if(id) {
				$.post('/crm/course-package/add-course', JSON.stringify(data.field), function(result) {
					if (result.code == 0) {
						$.vtl.closeLayer();
						parent.refresh();
					}
				});
			}
			return false;
		});

		window.init = function(id) {

		}

		window.init(id);
	})
</script>
</body>
</html>
